<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    ul {
        list-style: none;
        margin: 0;
    }
    li {
        width: 200px;
        background-color: #ededed;
        border: 1px solid #000;
        margin-top: 5px;
        padding-left: 5px;
    }
</style>
<body>
    <!-- 10. 利用事件委托的方法，给一个无序列表的列表项添加点击更改背景色事件。简单说明思路。 -->
    <ul id="box">
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>
    <script>
        var box = document.getElementById("box");
        var lis = box.getElementsByTagName("li");
        for (var i = 0; i < lis.length; i++) {
            lis[i].onclick = function () {
                // 排除其他
                for (var i = 0; i < lis.length; i++) {
                    lis[i].style.backgroundColor = "#ededed";
                }
                // 保留自己
                this.style.backgroundColor = "skyblue";
            }
        }
    </script>
</body>
</html>